import java.util.HashMap;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

            String s = in.nextLine();
            int n=s.length();
            if(n<3) System.out.println(n);

            int left=0,right=0;
            int maxLen=2;
        HashMap<Character,Integer>map=new HashMap<>();
        while (right<n){
            map.put(s.charAt(right),right);
            right++;

            if (map.size()>2){
                int minIndex=Integer.MAX_VALUE;

                for (int value: map.values()){
                    minIndex=Math.min(minIndex,value);
                }

                map.remove(s.charAt(minIndex));
                left=minIndex+1;
            }

            maxLen=Math.max(maxLen,right-left);

        }
        System.out.println(maxLen);
    }
}